package com.changgou.gateway.web.filter;

import org.springframework.stereotype.Component;

@Component
public class UrlFilter {

    //都是需要令牌才能访问的路径
    public static String filterPath = "/api/wseckillorder,/api/seckill,/api/wxpay,/api/wxpay/**,/api/worder/**,/api/user/**,/api/address/**,/api/wcart/**,/api/cart/**,/api/categoryReport/**,/api/orderConfig/**,/api/order/**,/api/orderItem/**,/api/orderLog/**,/api/preferential/**,/api/returnCause/**,/api/returnOrder/**,/api/returnOrderItem/**";

    //此方法,返回是否需要令牌,true需要令牌的访问路径,false,不需要令牌的访问路径
    public static boolean hasAuthorize(String url){
        String[] split = filterPath.replace("**", "").split(",");

        for (String path : split) {
            //path : /api/user/
            //url  : /api/user
            //" false /api/user".startWith("/api/user/")  -> 代表的含义,不需要经过令牌认证的路径
//            url.startsWith("path");

            if(path.startsWith(url)){
                return true;
            }else if(url.startsWith(path)){
                //url : /api/user/search
                //path: /api/user/
                return true;
            }

        }

        return false;
    }
}
